package com.example.backend;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RedisConsumer implements MessageListener {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("Received event: " + message.toString());

        // 假设 AI 回复消息
        String aiResponse = "AI 回复：" + message.toString();

        // 将 AI 回复发送到 answerQueue 队列
        redisTemplate.convertAndSend("answerQueue", aiResponse);
        System.out.println("AI 回复已发送到 answerQueue: " + aiResponse);
    }
}

